<template>
  <div class="main">
    <!--用户信息-->
    <div class="user-info">
      <div class="head">
        <VanImg fit="fill" width="100%" height="100%" :src="userHead"></VanImg>
      </div>
      <div class="base">
        <span class="name">{{userName}}</span>
        <span class="account">{{userAccount}}</span>
      </div>
    </div>
    <!--用户相关-->
    <div class="user-rel">
      <div @click="onRoute(rel.route)" v-for="(rel, index) in relData" :key="index">
        <span>{{rel.num}}</span>
        <span>{{rel.name}}</span>
      </div>
    </div>
    <!--订单相关-->
    <div class="user-order">
      <div class="order-base">
        <span class="order-title">我的订单</span>
        <span @click="toOrder()" class="order-check">查看全部订单</span>
      </div>
      <Divider style="margin: 0"/>
      <div class="order-func">
        <div @click="toOrder(func.type)" v-for="(func, index) in funcData" :key="index">
          <Icon :name="func.icon" color="lightskyblue"></Icon>
          <span>{{func.name}}</span>
        </div>
      </div>
      <div class="carry">
        <div class="carry-title">
          <span>最新物流</span>
          <span>02:21</span>
        </div>
        <div class="carry-info">
          <div class="carry-img">
            <VanImg fit="fill" width="100%" height="100%"
                    src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=394259797,1684286832&fm=26&gp=0.jpg"></VanImg>
          </div>
          <div class="carry-base">
            <span class="carry-status">运输中</span>
            <span class="carry-msg">快件在【长沙星沙中转场】完成中转，正在发往【广州天河中转场】</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {Image as VanImg, Divider, Icon} from 'vant'

export default {
  name: 'User',
  components: {
    VanImg,
    Divider,
    Icon
  },
  data () {
    return {
      userHead: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fi1.hdslb.com%2Fbfs%2Farchive%2F7ea7406d87a0c2b22ce29bed0ab6201d74b0b302.jpg&refer=http%3A%2F%2Fi1.hdslb.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1615544952&t=6ab7b707f340352aaaebaeb8af7506db',
      userName: '新用户',
      userAccount: 'AE86',
      relData: [],
      funcData: []
    }
  },
  created () {
    this.relData = [
      {
        num: 2,
        name: '收藏夹',
        route: 'collect'
      },
      {
        num: 7,
        name: '关注',
        route: 'interest'
      },
      {
        num: 14,
        name: '足迹',
        route: 'history'
      },
      {
        num: 0,
        name: '红包卡券',
        route: 'coupon'
      }
    ]

    this.funcData = [
      {
        icon: 'bill',
        name: '待付款',
        type: 'pay'
      },
      {
        icon: 'cluster',
        name: '待发货',
        type: 'send'
      },
      {
        icon: 'cart-circle',
        name: '待收货',
        type: 'receive'
      },
      {
        icon: 'comment',
        name: '评价',
        type: 'comment'
      },
      {
        icon: 'gold-coin',
        name: '退款/售后',
        type: 'refund'
      }
    ]
  },
  methods: {
    onRoute (routeName) {
      this.$router.push({path: routeName})
    },
    toOrder (orderType) {
      if (orderType === 'refund') {
        this.$router.push({path: 'refund'})
      } else {
        let type = orderType || 'all'
        this.$router.push({name: 'Order', params: {type}})
      }
    }
  }
}
</script>

<style scoped lang="less">
  .main {
    font-size: 0.1rem;
    padding: 0.2rem;
  }

  .user-info {
    display: flex;
    margin: 0.1rem 0.1rem 0.1rem;

    .head {
      flex-shrink: 0;
      height: 1rem;
      width: 1rem;
      margin-right: 0.2rem;
      border-radius: 50%;
      overflow: hidden;
    }

    .base {
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .name {
        color: black;
      }

      .account {
        color: darkgrey;
      }

    }
  }

  .user-rel {
    display: flex;
    justify-content: space-around;

    div {
      display: flex;
      flex-direction: column;
      width: 1.5rem;
      text-align: center;

    }
  }

  .user-order {
    margin: 0.2rem 0 0.1rem;
    background-color: white;
    border-radius: 0.2rem;
    padding: 0.2rem;

    .order-base {
      margin: 0.1rem 0 0.2rem;
      display: flex;
      justify-content: space-between;

      .order-title {
        font-size: 0.25rem;
        color: black;
        font-weight: bold;
      }

      .order-check {
        font-size: 0.1rem;
        color: orangered;
      }
    }

    .order-func {
      display: flex;
      flex-direction: row;
      justify-content: space-around;
      font-size: 0.5rem;
      margin: 0.2rem 0 0.2rem;

      div {
        text-align: center;
        display: flex;
        flex-direction: column;
        align-content: space-between;

        span {
          font-size: 0.1rem;
        }
      }
    }

    .carry {
      background-color: whitesmoke;
      font-size: 0.1rem;
      color: darkgrey;
      padding: 0.2rem;
      border-radius: 0.2rem;

      .carry-title {
        display: flex;
        justify-content: space-between;

      }

      .carry-info {
        display: flex;
        margin: 0.1rem 0.1rem 0.1rem;

        .carry-img {
          flex-shrink: 0;
          height: 0.8rem;
          width: 0.8rem;
          margin-right: 0.2rem;
          border-radius: 0.2rem;
          overflow: hidden;
        }

        .carry-base {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          min-width: 0;

          .carry-status {
            color: lightskyblue;
          }

          .carry-msg {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }

        }
      }
    }
  }
</style>
